﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpiderHelper
{
    public class EnterPoint
    {
        public void Start()
        {

            //这部分是查阅新闻数据
            //"开始查询".Debug();
            SpiderHelper.Model.CollectionSite site = new SpiderHelper.Model.CollectionSite();
            List<SpiderHelper.Model.CollectionSite> sites = site.GetList();
            SpiderHelper.Index.Default visitor = new SpiderHelper.Index.Default();

            //while (true)
        //{
        StartVisit:
            foreach (SpiderHelper.Model.CollectionSite _site in sites)
            {
                SpiderHelper.Model.CollectionChannel channel = new SpiderHelper.Model.CollectionChannel();
                List<SpiderHelper.Model.CollectionChannel> channels = new SpiderHelper.Model.CollectionChannel().GetList(Convert.ToInt32(_site.Id));

                foreach (SpiderHelper.Model.CollectionChannel c in channels)
                {
                    DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
                    List<SpiderHelper.Model.TempDoc> docs = visitor.GetDocsFromChannel(c, db);
                    foreach (SpiderHelper.Model.TempDoc doc in docs)
                    {
                        SpiderHelper.Model.TempDoc _doc = new Model.TempDoc();
                        _doc.Link = doc.Link;
                        bool exist = db.IsExist(_doc);
                        if (!exist)
                        {
                            if (doc.Content.Length > 10)
                            {
                                db.Insert(doc);
                            }
                        }
                    }
                    db.Commit();
                    db.Dispose();
                    System.Threading.Thread.Sleep(1000);
                }

            }
            goto StartVisit;
            //}
            //  Console.ReadLine();
        }
        /// <summary>
        /// 初始化频道
        /// </summary>
        public void Init()
        {
            Tools.Sina.SinaVisitor visitor = new Tools.Sina.SinaVisitor();
            visitor.InitSinaChannels();
        }
    }
}
